package com.star.es.entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.star.es.entity.ESQuery.ESQueryBuilder;

import lombok.Data;

/**
 * 查询参数DTO
 * 用于接收前端查询参数
 * @author Administrator
 *
 */
@Data
@SuppressWarnings("serial")
public class QueryParam implements Serializable{
	
	private static final String DEFAULT_INDEX="article"; // 默认查询的索引 
	
	private List<String> index;
	private List<String> type;
	/**
	 * 查询参数
	 */
	private Map<String, Object> query;
	/**
	 * 过滤参数
	 */
	private Map<String, Object> filter;
	/**
	 * 范围参数
	 */
	private Map<Range, Object> range;
	
	public QueryParam() {
		super();
		this.index=new ArrayList<>();
		this.type=new ArrayList<>();
		this.query=new HashMap<>();
		this.filter=new HashMap<>();
		this.range=new HashMap<>();
	}
	
	/**
	 * 转化为ESQuery参数
	 * @return
	 */
	public ESQuery convertESQuery(){
		ESQueryBuilder builder=new ESQueryBuilder();
		if (index.size()==0){
			builder.index(DEFAULT_INDEX);
		}
		builder.type(type);
		return builder.build();
	}
	

}
